import datetime
from datetime import timedelta

from app.monitor_logs.handlers.service_handler import get_abnormal_service
from app.monitor_logs.handlers.url_handler import kibana6_log_app_url
from app.tools_url_shorten.handlers import create_short_link
from common.notice_tools import NoticeTools
from common.database import SessionLocal
from common.elastic import get_es
from setting import config


def abnormal_service(key, abnormal_server, cst_begin_time, cst_end_time, notice_team, exclude_k_abnormal_count, character_log, alarm_count,
                     kibana_app_url, session):
    short_link = create_short_link(session, kibana_app_url)
    content = "[`告警`] 应用服务日志异常\n>" \
              f"<font color=\"comment\">告警服务</font>:   <font color=\"comment\">{abnormal_server}</font>\n" \
              f"<font color=\"comment\">时间区间</font>:   <font color=\"comment\">{cst_begin_time}~{cst_end_time}</font>\n " \
              f"<font color=\"comment\">通知人员</font>:   <font color=\"comment\">{notice_team}</font>\n " \
              f"<font color=\"comment\">错误计数</font>:   <font color=\"warning\">{exclude_k_abnormal_count}</font>\n" \
              f"<font color=\"comment\">日志特征</font>:   <font color=\"warning\">{character_log}</font>\n " \
              f"<font color=\"comment\">告警次数</font>:   `{alarm_count}`\n " \
              f"<font color=\"comment\">点击查看</font>:    [详情信息]({config.SHORT_URL}?short_link={short_link})\n"
    NoticeTools.send_wechatbot(key=key, content=content)

# if __name__ == '__main__':
#     abnormal_service_notice(key="4b62c9fe-9cf1-40c3-be22-5d48323039f2")
